﻿using System;
using System.ComponentModel;
using System.Linq;

using Model;

namespace SqlExamples
{
    //查询数据库以找出Tim全部未解决的缺陷
    [Description("Listing 12.1")]
    class ShowAllOpenDefectsAssignedToTim
    {
        static void Main()
        {
            //创建用于操作的上下文
            using (var context = new DefectModelDataContext())
            {
                //打开控制台日志，在控制台输出所执行的SQL命令
                context.Log = Console.Out;
                //查询数据库找出Tim
                User tim = (from user in context.Users
                            where user.Name=="Tim Trotter"
                            select user).Single();
                //查询数据库找出Tim为解决的缺陷
                var query = from defect in context.Defects
                            where defect.Status != Status.Closed
                            where defect.AssignedTo == tim
                            select defect.Summary;

                foreach (var summary in query)
                {
                    Console.WriteLine(summary);
                }
            }
        }
    }
}
